package in.muton.edushare.pages.group;

import in.muton.edushare.pages.common.PollsStatsPanel;
import in.muton.edushare.poll.panels.PollList;
import in.muton.edushare.url.URLLoader;

import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.CSSPackageResource;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.constants.URLConstants;
import com.edushare.common.dao.PollStatsDAO;

public class GroupPoll extends GroupBase {

	public GroupPoll(PageParameters params) {
		super(params);
		if (!getLoggedInUser().isGroupMember(super.groupModel.getObject())) {
			throw new RestartResponseException(URLLoader
					.getPageClass(URLConstants.UNAUTHORIZED_PATH));
		}
		add(CSSPackageResource
				.getHeaderContribution(PollList.class, "Poll.css"));
		PollStatsDAO ps = new PollStatsDAO(getSessionORMInterface());
		add(new PollsStatsPanel("statsFrag", ps.getTotalPolls(getGroupModel()
				.getObject()), ps.getOpenPolls(getGroupModel().getObject()), ps
				.getClosedPolls(getGroupModel().getObject()), ps
				.getDraftPolls(getGroupModel().getObject())));
		add(new PollList("activePanel", getGroupModel().getObject(), this));
	}

	@Override
	protected String getActivePage() {
		return "groupPoll";
	}

	@Override
	public String getPageTitle() {
		return "Polls | " + super.groupModel.getObject().getGroupName() + " | "
				+ ApplicationConstants.APPLICATION_NAME;
	}

}
